Next | Prev | Up | Top | Contents | Index

Testing Cycle Counter Precision.

The program in Example A-1 is a simple utility that gets the cycle counter precision using syssgi() and displays it. The timer precision (in bits, either 32 or 64) is displayed to standard output. Also, the precision is returned by the program, so it can be tested in a shell script in the $status shell variable.

Example A-1 : Program to Return Cycle Counter Precision

/*****************************************************************************
||
|| This program makes the value returned by syssgi(SGI_CYCLECNTR_SIZE)
|| accessible at the command line.  The output display can be read, or
|| tested in a shell script.  The value is also returned, so it can
|| be tested in the $status variable.
||
*****************************************************************************/
#include <sys/syssgi.h>     /* for syssgi(), SGI_QUERY_CYCLECNTR */
#include <stdio.h>
int main(int argc, char *argv[])
{
    unsigned int tbc = syssgi(SGI_CYCLECNTR_SIZE);
    int arg, quiet = 0;
    for (arg=1; arg<argc; ++arg)
    {
        if (0==strcmp(argv[arg],"-q"))
        {
            quiet = 1;
        }
        else /* includes case of -h */
        {
            printf("%s [-h | -q]\n",argv[0]);
            printf("\tReport the precision of the hardware cycle counter.\n");
            printf("\tPrecision in bits displayed to stdout unless -q.\n");
            printf("\tPrecision in bits returned as status.\n");
            return tbc;
        }
    }
    if (!quiet)
        printf("%d bits in the cycle counter\n",tbc);
    return tbc;
}

Next | Prev | Up | Top | Contents | Index